#include "StaticMeshComponent.h"

#include "Runtime/Engine/Material.h"
#include "Runtime/Engine/MaterialShared.h"
#include "Runtime/Rendering/NaniteSceneProxy.h"
#include "Runtime/Rendering/StaticMeshSceneProxy.h"

namespace Alice
{
    StaticMeshComponent::StaticMeshComponent()
    {
        mStaticMesh=new StaticMesh;
        mStaticMesh->Build();
        Material*material=new Material;
        Shader* vertexShader=Shader::GetOrCreateShaderFromShaderPath<VertexShader>(EMeshPass::BasePass,"Res/test.vsb");
        Shader* pixelShader=Shader::GetOrCreateShaderFromShaderPath<PixelShader>(EMeshPass::BasePass,"Res/test.fsb");
        material->SetShader(EMeshPass::BasePass,EShaderFrequency::SF_Vertex,vertexShader);
        material->SetShader(EMeshPass::BasePass,EShaderFrequency::SF_Pixel,pixelShader);
        mOverrideMaterials.push_back(material);
    }
    MaterialInterface* StaticMeshComponent::GetMaterial(int32 inIndex)
    {
        return mOverrideMaterials[0];
    }

    void StaticMeshComponent::CreateRenderState_Concurrent(FRegisterComponentContext* Context)
    {
        MeshComponent::CreateRenderState_Concurrent(Context);
    }
    PrimitiveSceneProxy* StaticMeshComponent::CreateSceneProxy()
    {
        FMaterialAudit material{};
        return CreateStaticMeshSceneProxy(material,false);
    }
    PrimitiveSceneProxy* StaticMeshComponent::CreateStaticMeshSceneProxy(FMaterialAudit& NaniteMaterials, bool bCreateNanite)
    {
        return new StaticMeshSceneProxy(this);
    }
}
